package com.queclink.ycm.thread;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2021-12-28 09:24:00
 */
public class ThreadLocalContextHolder {

    /**
     * 不同业务设置不同的业务场景，如：业务A设置值为1，业务B设置值为2...
     */
    private static ThreadLocal<Integer> sceneThreadLocal = new ThreadLocal<>();

    public static Integer getScene() {
        return sceneThreadLocal.get();
    }

    public static void initScene(Integer scene) {
        if (ThreadLocalContextHolder.sceneThreadLocal == null) {
            ThreadLocalContextHolder.sceneThreadLocal = new ThreadLocal<>();
        }
        ThreadLocalContextHolder.sceneThreadLocal.set(scene);
    }

    public static void clearScene() {
        initScene(null);
    }
}
